package com.homedo.odin.solution.controller.mng;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.contract.mng.SpecificationAuditReq;
import com.homedo.odin.solution.contract.mng.SpecificationDetailPriResp;
import com.homedo.odin.solution.contract.mng.SpecificationEditPriReq;
import com.homedo.odin.solution.contract.mng.SpecificationListPriResp;
import com.homedo.odin.solution.service.bizservice.mng.MngStandardsBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhaoxudong
 * @date: 2018/4/10 10:00
 * @Description:
 */
@Api(description = "行业规范", tags = {"Standard"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/mng/standards")
public class MngStandardsController extends BaseController<MngStandardsBizService> {

    @ApiOperation(value = "OMS_获取行业规范列表", notes = "OMS_获取行业规范列表", response = SpecificationListPriResp.class)
    @GetMapping
    public ResultData list(
            @ApiParam(value = "规范名称") @RequestParam(value = "specificationName", required = false) String specificationName,
            @ApiParam(value = "规范组") @RequestParam(value = "firstClassify", required = false) Integer firstCassify,
            @ApiParam(value = "规范分类") @RequestParam(value = "secondClassify", required = false) Integer secondClassify,
            @ApiParam(value = "规范状态（0：现行；1：即将实施；2：作废）") @RequestParam(value = "specificationStatus", required = false) Integer specificationStatus,
            @ApiParam(value = "规范来源（1：后台上传 2：前台上传）") @RequestParam(value = "formType", required = false) Integer formType,
            @ApiParam(value = "状态 0:已删除 10:待审核 20:审核通过 21:审核驳回 30:上架中 31:下架中") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码", required = true) @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页记录数", required = true) @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        SpecificationListPriResp resp = baseService
                .list(specificationName, firstCassify, secondClassify, specificationStatus, formType, status, pageNum,
                        pageSize);
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "OMS_获取规范详情", notes = "OMS_获取规范详情", response = SpecificationDetailPriResp.class)
    @GetMapping("/{specificationId}")
    public ResultData detail(@ApiParam("规范id") @PathVariable("specificationId") Long specificationId) {
        SpecificationDetailPriResp resp = baseService.detail(specificationId);
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "OMS_修改规范", notes = "OMS_修改规范")
    @PutMapping
    public ResultData edit(@RequestBody SpecificationEditPriReq req) {
        baseService.edit(req);
        return ResultData.newInstance();
    }

    @ApiOperation(value = "OMS_修改状态（审核、上下架、删除）", notes = "OMS_修改状态（审核、上下架、删除）")
    @PutMapping("/status")
    public ResultData status(@RequestBody SpecificationAuditReq req) {
        baseService.status(req);
        return ResultData.newInstance();
    }
}
